<template>
	<u-popup :show="showPrivacy" round="10">
		<view class="alert">
			<view class="title">葡共营小程序隐私政策</view>
			<view class="role">
				欢迎您使用葡共营小程序，为更好的保护您的隐私安全，请阅读并同意
				<view class="privacy-info">
					<checkbox-group @change="onPrivacyChange">
						<checkbox :value="checkPrivacy" :checked="false" :color="xThemeColor()" />
					</checkbox-group>
					<view class="protocol-prefix">我已阅读并同意</view>
					<view class="protocol" @click="onPrivacyContract">《查看隐私协议》</view>
				</view>

			</view>
			<button class="btn_login x-btn" open-type="agreePrivacyAuthorization"
				@agreeprivacyauthorization="onAgreePrivacyAuthorization">同意</button>
			<view class="not_login" @click="onCancelAgreePrivacyProtocol">暂不同意</view>
		</view>
	</u-popup>
</template>

<script>
	import {
		ThemeMixin
	} from '@/mixins/theme/xThemeMixin.js'
	export default {
		mixins: [ThemeMixin],
		components: {
			// XPrivacyAuthDialog,
		},
		props: {

		},
		data() {
			return {
				checkPrivacy: false,
				showPrivacy: false,
			}
		},
		mounted(){
			// this.load()
		},

		methods: {
			load() {
				wx.getPrivacySetting({
					success: res => {
						console.log("getPrivacySetting res=", res)
						if (res.needAuthorization) {
							// 需要弹出隐私协议
							this.showPrivacy = true
						} else {
							this.showPrivacy = false
							this.$emit('authorization', fale)
							// this.$store.dispatch('login').then(res => {
							// 	this.$emit("successLogin")
							// })
							// this.$emit("authed")
							// 用户已经同意过隐私协议，所以不需要再弹出隐私协议，也能调用已声明过的隐私接口
							// wx.getUserProfile()
							// wx.chooseMedia()
							// wx.getClipboardData()
							// wx.startRecord()
						}
					},
					fail: () => {},
					complete: () => {}
				})
			
			},
			
			onPrivacyChange(e) {
				this.checkPrivacy = e.detail.value[0]
			},

			onAgreePrivacyAuthorization() {
				if (!this.checkPrivacy) {
					this.$TOOLS.UNI.showToast("请勾选我已阅读并同意《隐私协议》")
					return;
				}
				this.showPrivacy = false
				this.$emit('authorization', true)
				// 用户同意隐私协议事件回调
				// 用户点击了同意，之后所有已声明过的隐私接口和组件都可以调用了
				// wx.getUserProfile()
				// wx.chooseMedia()
				// wx.getClipboardData()
				// wx.startRecord()
				// this.$emit("authed")
			},
			onPrivacyContract() {
				// 打开隐私协议页面
				wx.openPrivacyContract({
					success: () => {}, // 打开成功
					fail: () => {}, // 打开失败
					complete: () => {}
				})
			},

			onCancelAgreePrivacyProtocol() {
				this.showPrivacy = false
				this.$emit('authorization', fale)
			},

			


		},
	}
</script>

<style>
</style>